<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数组交集函数封装</title>
</head>

<body>

</body>
<script>
    let arr1 = [4, 9, 5, 5];
    let arr2 = [9, 4, 9, 8, 4, 5];

    let newArr = arr1.filter(function (item) {
        return arr2.indexOf(item) !== -1;
    }).reduce(function (pre, cur) {
        if (pre.indexOf(cur) == -1) {
            return pre.concat(cur);
        } else {
            return pre;
        }
    }, [])
    console.log(newArr)
</script>

</html>